<template>
  <a-drawer :title="title" :width="800" placement="right" :closable="false" @close="close" :visible="visible">
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="agencyCode" label="服务商编码">
          <a-input placeholder="请输入服务商编码" v-model="model.agencyCode" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId" label="用户id">
          <a-input-number v-model="model.userId" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="coachId" label="服务技师">
          <a-input-number v-model="model.coachId" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderNo" label="订单号">
          <a-input placeholder="请输入订单号" v-model="model.orderNo" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="transactionNo" label="商户订单号">
          <a-input placeholder="请输入商户订单号" v-model="model.transactionNo" />
        </a-form-model-item>
        <a-form-model-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          prop="payType"
          label="1 会员余额 2支付宝  3微信   4（钱包混合微信）5（钱包混合支付宝）"
        >
          <a-input-number v-model="model.payType" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalAmount" label="订单总金额">
          <a-input-number v-model="model.totalAmount" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serviceAmount" label="服务金额">
          <a-input-number v-model="model.serviceAmount" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carAmount" label="技师车费">
          <a-input-number v-model="model.carAmount" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialAmount" label="物料包金额">
          <a-input-number v-model="model.materialAmount" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payTime" label="支付时间">
          <a-date-picker showTime valueFormat="YYYY-MM-DD HH:mm:ss" v-model="model.payTime" />
        </a-form-model-item>
        <a-form-model-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          prop="payAmount"
          label="实际支付金额（微信、支付宝）"
        >
          <a-input-number v-model="model.payAmount" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payBalance" label="实际支付的余额">
          <a-input-number v-model="model.payBalance" />
        </a-form-model-item>
        <a-form-model-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          prop="preferentialAmount"
          label="优惠金额（优惠券不能与余额一起使用）"
        >
          <a-input-number v-model="model.preferentialAmount" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carPrice" label="出行费用">
          <a-input-number v-model="model.carPrice" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isAdd" label="是否是加钟订单">
          <a-input placeholder="请输入是否是加钟订单" v-model="model.isAdd" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="addOrderId" label="加钟订单的父id">
          <a-input-number v-model="model.addOrderId" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="timeLong" label="服务时长">
          <a-input-number v-model="model.timeLong" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="startTime" label="服务开始时间">
          <a-date-picker showTime valueFormat="YYYY-MM-DD HH:mm:ss" v-model="model.startTime" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endTime" label="服务结束时间">
          <a-date-picker showTime valueFormat="YYYY-MM-DD HH:mm:ss" v-model="model.endTime" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serverId" label="服务id">
          <a-input-number v-model="model.serverId" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serverName" label="当前服务名称">
          <a-input placeholder="请输入当前服务名称" v-model="model.serverName" />
        </a-form-model-item>
        <a-form-model-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          prop="payStatus"
          label="支付状态 0-待支付  1-已支付  2-已取消"
        >
          <a-input-number v-model="model.payStatus" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isDel" label="是否用户端展示 0-是  1-否">
          <a-input-number v-model="model.isDel" />
        </a-form-model-item>
        <a-form-model-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          prop="serverStatus"
          label="订单服务状态  1-已接单  2-已拒绝  3-已到达 4-服务开始  5-服务结束  6-加钟"
        >
          <a-input-number v-model="model.serverStatus" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="preferentialId" label="优惠券id">
          <a-input-number v-model="model.preferentialId" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="province" label="省">
          <a-input placeholder="请输入省" v-model="model.province" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="city" label="市">
          <a-input placeholder="请输入市" v-model="model.city" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="area" label="区">
          <a-input placeholder="请输入区" v-model="model.area" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lng" label="经度">
          <a-input placeholder="请输入经度" v-model="model.lng" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lat" label="纬度">
          <a-input placeholder="请输入纬度" v-model="model.lat" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="address" label="地址">
          <a-input placeholder="请输入地址" v-model="model.address" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name" label="姓名">
          <a-input placeholder="请输入姓名" v-model="model.name" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phone" label="手机号">
          <a-input placeholder="请输入手机号" v-model="model.phone" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>

    <div class="drawer-bootom-button">
      <a-button type="primary" @click="handleOk">确定</a-button>
      <a-button type="primary" @click="handleCancel">取消</a-button>
    </div>
  </a-drawer>
</template>

<script>
import { httpAction } from '@/api/manage'
import moment from 'moment'

export default {
  name: 'XhdjOrderInfoModal',
  data () {
    return {
      title: '操作',
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },

      confirmLoading: false,
      validatorRules: {},
      url: {
        add: '/xhdjOrderInfo/xhdjOrderInfo/add',
        edit: '/xhdjOrderInfo/xhdjOrderInfo/edit'
      }
    }
  },
  created () {},
  methods: {
    add () {
      //初始化默认值
      this.edit({})
    },
    edit (record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    close () {
      this.$emit('close')
      this.visible = false
      this.$refs.form.clearValidate()
    },
    handleOk () {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method)
            .then(res => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
              that.close()
            })
        } else {
          return false
        }
      })
    },
    handleCancel () {
      this.close()
    }
  }
}
</script>

<style lang="less" scoped>
/**Button按钮间距*/
.ant-btn {
  margin-left: 30px;
  margin-bottom: 30px;
  float: right;
}
/**抽屉按钮样式*/
.drawer-bootom-button {
  position: absolute;
  bottom: -8px;
  width: 100%;
  border-top: 1px solid #e8e8e8;
  padding: 10px 16px;
  text-align: right;
  left: 0;
  background: #fff;
  border-radius: 0 0 2px 2px;
}
</style>
